//
//  LGPatientRiskMonitorController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/8/2.
//  房颤 - 风险监测

#import "LGPatientRiskMonitorController.h"
#import "LGGetWebViewController.h"
#import "LGPatientRiskMonitorHeader.h"
#import "LGPatientRiskMonitorCell.h"
#import "LGBaseInfoHeaderView.h"
@interface LGPatientRiskMonitorController ()<UITableViewDelegate,UITableViewDataSource,LGPatientRiskMonitorHeaderDelegate,LGBottomButtonDelegate>
/**   */
@property (nonatomic , strong)LGPatientRiskMonitorHeader *headView;
/**   */
@property (nonatomic , strong)LGBottomButtonView *bottomView;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSDictionary *dataDic;
/**   */
@property (nonatomic , strong)NSArray *dataArray;
/**   */
@property (nonatomic , copy)NSString *editUrl;

@end

@implementation LGPatientRiskMonitorController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"风险检测";
    [self.view addSubview:self.tableView];
    if (self.canEdit == YES) {
        self.tableView.frame = CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight-viewPix(65)-bottomSafeBarHeight/4.0);
        [self.view addSubview:self.bottomView];
    }
    [self requestData:@""];
    
}

-(void)requestData:(NSString *)type{
    //全部-传空 1-患者自评 2-医评
    NSDictionary *parama = @{@"patient_id":self.patientid};
    if (type.length>0) {
        parama = @{@"patient_id":self.patientid,@"evaclient":type};
    }
    [RequestUtil withPOST:@"/doctor/patient.Profile/fcRiskAnalysisdata" parameters:parama withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            self.editUrl = LGNSString(returnData[@"eva_url"]);
            self.headView.dataDic = returnData;
            self.dataArray = returnData[@"tzs"];
            self.dataDic = returnData;
            [self.tableView reloadData];
        }
    } error:^(NSError *error) {
        
    }];
}

-(void)bottomButtonTouched{
    LGGetWebViewController *controller = [[LGGetWebViewController alloc]init];
    controller.urlStr = self.editUrl;
    [self.navigationController pushViewController:controller animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGPatientRiskMonitorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    cell.type = (indexPath.row == self.dataArray.count-1)?LGPositionTypeBottom:LGPositionTypeMiddle;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return viewPix(45);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LGBaseInfoHeaderView *headView = [[LGBaseInfoHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(45))];
    headView.editButton.hidden = YES;
    headView.titleLabel.text = @"体征监测";
    headView.dateLabel.text = LGNSString(self.dataDic[@"tzs_date"]);
    return headView;
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGPatientRiskMonitorCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headView;
    }
    return _tableView;
}

-(LGPatientRiskMonitorHeader *)headView{
    if(!_headView){
        _headView = [[LGPatientRiskMonitorHeader alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(540))];
        _headView.delegate = self;
    }
    return _headView;
}

-(LGBottomButtonView *)bottomView{
    if(!_bottomView){
        _bottomView = [[LGBottomButtonView alloc]initWithTitle:@"风险评分" color:@"#5E8EF5" type:LGBottomButtonTypeBack frame:CGRectMake(0, Screen_H-topBarHeight-viewPix(65)-bottomSafeBarHeight/4.0, Screen_W, viewPix(65)+bottomSafeBarHeight/4.0)];
        _bottomView.delegate = self;
    }
    return _bottomView;
}

@end
